<template>
	<view class="user_info_style">
		<view style="font-size: 40rpx;font-weight: bold;margin-top: 20rpx;">提示</view>
		<view style="font-size: 30rpx;margin-top: 30rpx;">获取用户信息</view>
		<view class="bottom_btn">
			<view class="cancle_style" @click="cancle">取消</view>
			<button class="authorization_style" open-type="getUserInfo" @getuserinfo="wxGetUserInfo">授权</button>
		</view>
	</view>
</template>

<script>
	var that = null;
	export default {
		data() {
			return {
				
			};
		},
		props:{
			callback:{
				type:Function
			}
		},
		methods:{
			cancle(){
				this.callback('0');
			},
			refreshUserInfo(){
				this.$request.post({
					url: "/mUser/userInfo",
					success(res) {
						if(res != null){
							console.log(res);
							uni.setStorageSync('userInfo', res.userInfo);
							that.callback('1');
						}
					}
				});
			},
			wxGetUserInfo(){
				that = this;
				uni.getUserInfo({
					success: (res) => {
						console.log(res);
						let userInfo = JSON.parse(res.rawData);
						this.$request.post({
							url: "/mUser/editUser",
							data:{
								user_nick_name:userInfo.nickName,
								user_portrait:userInfo.avatarUrl,
								user_gender:userInfo.gender,
								province:userInfo.province,
								city:userInfo.city
							},
							success(res) {
								that.refreshUserInfo();
							},
							fail(res){
								console.log(res);
							}
							
						});
					},
					fail: () => {
						console.log("未授权");
					}
				})
			}
		}
	}
</script>

<style lang="stylus" scoped>
	.user_info_style{
		width 500rpx;
		display flex;
		flex-direction column;
		border-radius 10rpx;
		overflow hidden;
		text-align center;
		.bottom_btn{
			
			// border-top-color #eee;
			// border-style solid;
			// border-width 1rpx;
			display flex;
			margin-top 30rpx;
			padding-bottom 0rpx;
			bottom 0rpx;
			margin-bottom 0rpx;
			height 88rpx;
			line-height 88rpx;
			.cancle_style{
				flex 1;
				font-size: 30rpx;
				background-color #fff;
			}
			.authorization_style{
				flex 1;
				background-color #fff;
				font-size: 30rpx;
			}
		}
	}
</style>
